﻿using Mes.Pendant.SupplierInterface;
using Mes.Pendant.SupplierInterface.SupplierDto;
using Mes.Pendant.Warehousings;
using Mes.Pendant.Warehousings.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Mes.Pendant.Web.Controllers
{
    public class WarehousingController : Controller
    {
        private readonly IWarehousingService _warehousingService;

        public WarehousingController(IWarehousingService warehousingService)
        {
            _warehousingService = warehousingService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Add()
        {
            return View();
        }

        public IActionResult WarehousingList()
        {
            return View();
        }

        public IActionResult Update(int id)
        {
            ViewBag.id = id;
            return View();
        }

        public async Task<int> AddWarehousing(WarehousingDto warehousingDto)
        {
            var result = await _warehousingService.AddWarehousing(warehousingDto);
            return result;
        }

        public async Task<JsonResult> GetWarehousingList(string? warehousingCode, string? warehousingName, bool? state, int page = 1, int limit = 10)
        {
            var result = await _warehousingService.GetWarehousingList(warehousingCode, warehousingName, state, page, limit);
            return Json(new { data = result.Queryable, count = result.RowCount, code = 0 });
        }

        public async Task<int> DeleteWarehousing(int id)
        {
            var result = await _warehousingService.DeleteWarehousing(id);
            return result;
        }

        public async Task<JsonResult> GetWarehousingInfo(int id)
        {
            var list = _warehousingService.GetWarehousingInfo(id);
            return Json(new { data = list.Result });

        }

        public async Task<int> UpdateWarehousing(WarehousingDto warehousingDto)
        {
            var result = await _warehousingService.UpdateWarehousing(warehousingDto);
            return result;
        }
    }
}
